<?php
namespace Home\Controller;
use Think\Controller;
class IndexController extends Controller {
    public function index(){
        // 现有名额数量记录
        $res1 = M('cutnum')->group('userId')->field('sum(num) as number,userId')->order('number desc')->limit('0,10')->select();

        foreach($res1 as $k=>$v){
            $ids[] = $v['userid'];
        }

        $getid = implode(',',$ids);

        if($getid){
            $res_user = M('user')->where('id in ('.$getid.')')->select();
        }

        foreach($res1 as $k=>$v){
            foreach($res_user as $k1=>$v1){

                if($v['userid'] == $v1['id']){

                    $res1[$k]['level'] = $v1['level'];
                    $res1[$k]['user'] = $v1['user'];
                }
            }
        }

        $getlevel = ['1'=>'普通会员','2'=>'vip会员','3'=>'天使合伙人','4'=>'梦想合伙人'];

        foreach($res1 as $k=>$v){
            $res1[$k]['level'] = $getlevel[$v['level']];
            $res1[$k]['rank'] = $k+1;
        }

        $this->assign('list',$res1);
        $this->display();
    }

  




}